package com.example.wac.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.example.wac.mail.SendMail;
import com.example.wac.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author wuancheng
 * @description
 * @date 2022-01-05 11:16:00
 */

@Component
@Slf4j
public class StockJob implements SimpleJob {

    @Autowired
    UserService userService;

    @Autowired
    SendMail sendMail;

    private final String from = "wacnihao@163.com";

    private final String subject = "今天又是元气满满的一天";

    @Override
    public void execute(ShardingContext shardingContext) {
        // 分片总数
        int shardingTotalCount = shardingContext.getShardingTotalCount();
        // 分片项
        int shardingItem = shardingContext.getShardingItem();
//        String shardingParameter = shardingContext.getShardingParameter();
//        String jobParameter = shardingContext.getJobParameter();
//        log.info("shardingTotalCount:" + shardingTotalCount + "---shardingItem:" + shardingItem + "---shardingParameter" + shardingParameter + "---jobParameter" + jobParameter);
//        List<User> userList = userService.list(shardingTotalCount, shardingItem);
//        userList.forEach(user -> {
//            ToEmail email = ToEmail.builder().from(from).tos(user.getEmail()).subject(subject).content("早上好"+user.getName()).build();
//            sendMail.asyncCommonEmail(email);
//        });
    }
}
